package pack2;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import matchingPLS2TF.FlickrUserMethods;
import matchingPLS2TF.PLSUser;



public class Main2Matching {

	public static void main (String[] args) throws Exception{
		
			  
			List<PLS> pls = new ArrayList<PLS>();
			//FlickrUserMethods.loadPLSUser(pls, "C:\\Users\\Alket\\junocode\\DataTel\\133plsevents.txt");
			
			Collections.sort(pls);
			
		    Map<PLS, List<PLSUser>>	data = new HashMap<PLS, List<PLSUser>>();
		    Set<String> excluded = new HashSet<String>();
		    
			List<PLSUser> pls_user ;
			
			for (int i = 0; i < pls.size(); i++) {	
			
				//pls_user = new ArrayList<PLSUser>();
				if((pls.size() -(i+1))==0){
					break;
				}
				String username_i1 = pls.get(i+1).h;
				String username_i = pls.get(i).h;
				
				System.out.println(username_i);
				
					double fl_lat = pls.get(i).lat;
					double fl_lon = pls.get(i).lon;
					long celllac = pls.get(i).cellac;
					long ts_pls_user = pls.get(i).time;
					pls_user = new ArrayList<PLSUser>();
					pls_user = PLSMethods.getPLS("C:\\Users\\Alket\\junocode\\FlickrAPI\\AllData",celllac, ts_pls_user);
					data.put(pls.get(i), pls_user);
					if(!(username_i.equals(username_i1))){
						
						//FlickrUserMethods.print2("PLS2PLS_"+username_i+",10min.txt", data);
						System.out.println("stampo file per "+username_i);
					
						// cancello per prepararmi al prossimo utente
						data = new HashMap<PLS, List<PLSUser>>();
						//excluded = new HashSet<String>();
					}
				} 
	    }
		
 		
//        String sorted_path = "C:/Users/Alket/junocode/DataTel/PLS2PLS"; 
//        sortedPLS(sorted_path);
	

	public static void sortedPLS(String folder) throws Exception{

		 File Folder = new File(folder);
		 File files[];
		 files = Folder.listFiles();
		 List<PLS2PLS>list = null;
		 
		try{
	        String line = "";

	        if(files.length>1){
	        	
	         for(int i = 0;i<files.length; i++){
	           
				BufferedReader br = new BufferedReader(new FileReader((files[i])));
	              
				  list = new ArrayList<PLS2PLS>();
				  while((line = br.readLine())!=null){
					  String[]r = line.split(",");	
						String h1 = r[0];
						int i1 = Integer.parseInt(r[1]);
						long c1 = Long.parseLong(r[2]);
						long t1 = Long.parseLong(r[3]);
						double lat1 = Double.parseDouble(r[4]);
						double lon1 = Double.parseDouble(r[5]);
						double rad1 = Double.parseDouble(r[6]);
						String h2 = r[7];
						int i2 = Integer.parseInt(r[8]);
						long c2 = Long.parseLong(r[9]);
						long t2 = Long.parseLong(r[10]);
						double lat2 = Double.parseDouble(r[11]);
						double lon2 = Double.parseDouble(r[12]);
						double rad2 = Double.parseDouble(r[13]);
						
						list.add(new PLS2PLS(h1, i1, c1, t1, lat1, lon1, rad1, h2, i2, c2, t2, lat2, lon2,rad2 ));
					
				  }br.close();
				  String sortedfile = "Sorted"+""+files[i].getName(); 
				  Collections.sort(list);
				  PLSMethods.printPLS2PLS(sortedfile, list);
	           }
	        }
	        
		 }catch( Exception ex){
		    	ex.printStackTrace(); 
	     }
	}

	
}
